#define _CRT_SECURE_NO_WARNINGS 1
lass Solution{
public:
    long long maximumSumOfHeights(vector<int>&maxHeights) {
        int len = maxHeights.size();
        long long sum = 0;
        for (int i = 0; i < len; i++) {
           long long ans = 0;
           int k = maxHeights[i];
           ans += k;
           int l = i - 1;
           int r = i + 1;
           while (l >= 0) {
               if (maxHeights[l] >= k) {
                   ans += k;

               }
else {
   ans += maxHeights[l];
   k = maxHeights[l];
}

l--;
}

k = maxHeights[i];
while (r < len) {
    if (maxHeights[r] <= k) {
        ans += maxHeights[r];
         k = maxHeights[r];
    }
else {
   ans += k;
}

r++;
}
//  cout<<"ans=="<<ans<<" "<<i<<endl;
 sum = max(ans,sum);
}
return sum;
}
};